﻿namespace Hidistro.UI.SaleSystem.CodeBehind
{
    using Hidistro.Entities.Commodities;
    using Hidistro.SaleSystem.Catalog;
    using Hidistro.UI.Common.Controls;
    using Hidistro.UI.SaleSystem.Tags;
    using System;
    using System.Collections.Generic;
    using System.Web.UI.HtmlControls;

    public class VSubPage : VshopTemplatedWebControl
    {
        private int categoryId;
        private HtmlGenericControl ctitle;
        private HtmlGenericControl clist;
        private wnxd_SortList list;
        protected override void AttachChildControls()
        {
            int.TryParse(this.Page.Request.QueryString["CategoryId"], out this.categoryId);
            CategoryInfo category = CategoryBrowser.GetCategory(this.categoryId);
            if (category == null) base.GotoResourceNotFound("无法找到该分类");
            if (category.ParentCategoryId != 0) this.Page.Response.Redirect("/Vshop/ProductList.aspx?categoryId=" + category.CategoryId);
            PageTitle.AddSiteNameTitle(category.Name);
            this.ctitle = (HtmlGenericControl)this.FindControl("ctitle");
            this.clist = (HtmlGenericControl)this.FindControl("clist");
            this.list = (wnxd_SortList)this.FindControl("list");
            if (!this.Page.IsPostBack)
            {
                this.ctitle.InnerText = category.Name;
                List<CategoryInfo> list = CategoryBrowser.GetMaxSubCategories(this.categoryId, 0x3e8) as List<CategoryInfo>;
                for (int i = 0; i < list.Count; i++)
                {
                    this.clist.InnerHtml += string.Format("<li><a href=\"/Vshop/ProductList.aspx?categoryId={0}\">{1}</a></li>", list[i].CategoryId, list[i].Name);
                }
                this.clist.InnerHtml += "<li><a href=\"/Vshop/CategoryPage.aspx\">全部分类</a></li>";
                this.list.DataSource = list;
                this.list.DataBind();
            }
        }
        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "skin-vSubPage.html";
            }
            base.OnInit(e);
        }
    }
}